package utils

import (
	"github.com/aliyun/aliyun-oss-go-sdk/oss"
	"github.com/astaxie/beego"
)

const (
	AccessKeyID     = "LTAIA72ZmeEmOHDs"
	AccessKeySecret = "PvpGlac0OL2QGxNrCza92N9OK3MG9B"
	RoleArn         = "acs:ram::1801171283427085:role/aliyunosstokengeneratorrole"
	SessionName     = "maternal-baby"
	Endpoint        = "oss-cn-beijing.aliyuncs.com"
)

func GetImageUrl(ossImageName, op string) string {
	if ossImageName == "" {
		return ""
	}
	// 创建OSSClient实例。
	client, err := oss.New(Endpoint, AccessKeyID, AccessKeySecret)
	if err != nil {
		beego.Error(err)
		return ""
	}

	// 获取存储空间。
	bucket, err := client.Bucket(SessionName)
	if err != nil {
		beego.Error(err)
		return ""
	}

	imageUrl, err := bucket.SignURL(ossImageName, oss.HTTPGet, 600, oss.Process(op))
	if err != nil {
		beego.Error(err)
		return ""
	}
	return imageUrl
}
